<script>
	import { mapState,mapMutations } from 'vuex'
	export default {
		onLaunch: function() {
			console.log('App Launch')
			const hasLogin = uni.getStorageSync('hasLogin');  // 登录状态获取
			const userInfo = uni.getStorageSync('userInfo');
			if(hasLogin){
				this.storeLogin(userInfo)
			}
			const updateManager = uni.getUpdateManager();  // 小程序更新管理工具
			updateManager.onCheckForUpdate(function (res) {
			  // 请求完新版本信息的回调
			  console.log(res.hasUpdate);
			});
			updateManager.onUpdateReady(function (res) {
			  uni.showModal({
			    title: '更新提示',
			    content: '新版本已经准备好，是否重启应用？',
			    success(res) {
			      if (res.confirm) {
			        // 新的版本已经下载好，调用 applyUpdate 应用新版本并重启
			        updateManager.applyUpdate();
			      }
			    }
			  });
			});
			updateManager.onUpdateFailed(function (res) {
			  // 新的版本下载失败
			  console.log(res)
			  // uni.showToast({
			  // 	title:"获取最新版本失败，请退出重试~", icon: "none"
			  // })
			});
		},
		onShow: function() {
			swan.setPageInfo({
				title: '百度小程序——小明的校园美食点评：高校约饭、分享、交友神器',
				keywords: '百度,百度小程序,美食,社交,校园',
				description: '小明的校园美食点评，一款致力于为高校学生提供便捷服务，为公益活动提供免费宣传的宝藏小程序',
				articleTitle: '小明的校园美食点评：高校约饭、分享、交友神器',
				releaseDate: '2020-11-22 12:01:30',
				image: [
				  './static/logo1.png'
				],
				success: res => {
					console.log('setPageInfo success', res);
				},
				fail: err => {
					console.log('setPageInfo fail', err);
				}
			})
		},
		onHide: function() {
			console.log('App Hide')
			if(this.hasLogin){
				uni.setStorageSync('hasLogin', true)
				uni.setStorageSync('userInfo', this.userInfo)
			}else{
				uni.setStorageSync('hasLogin', false)
				uni.setStorageSync('userInfo', {})
			}
		},
		methods:{
			...mapMutations({
				storeLogin: 'login'
			}),
			getCurrentPages(){
		　　var pages = getCurrentPages();    //获取加载的页面
		　　var currentPage = pages[pages.length - 1];  //获取当前页面的对象
		　　var url = currentPage.route;  //当前页面url
		　　var options = currentPage.options;   //获取url中所带的参数
		　　//拼接url的参数
		　　var currentPage= url + '?';
		　　for (var key in options) {
		　　　　var value = options[key]
		　　　　currentPage+= key + '=' + value + '&';
		　　}
		　　currentPage= currentPage.substring(0, currentPage.length - 1);
		　　return currentPage;
			},
		},
		computed:{
		  ...mapState(['hasLogin', 'userInfo'])
		}
	}
</script>

<style>
	/*每个页面公共css */
	@import './style/base.css';
@font-face {font-family: "iconfont";
  src: url('https://at.alicdn.com/t/font_2198848_8lqmn8qn3tj.eot?t=1606296616184'); /* IE9 */
  src: url('https://at.alicdn.com/t/font_2198848_8lqmn8qn3tj.eot?t=1606296616184#iefix') format('embedded-opentype'), /* IE6-IE8 */
  url('https://at.alicdn.com/t/font_2198848_8lqmn8qn3tj.woff?t=1606296616184') format('woff'),
  url('https://at.alicdn.com/t/font_2198848_8lqmn8qn3tj.ttf?t=1606296616184') format('truetype'), /* chrome, firefox, opera, Safari, Android, iOS 4.2+ */
  url('https://at.alicdn.com/t/font_2198848_8lqmn8qn3tj.svg?t=1606296616184#iconfont') format('svg'); /* iOS 4.1- */
}

.icon {
  font-family: "iconfont" !important;
  font-size: 16px;
  font-style: normal;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.iconarrow-right:before {
  content: "\e60b";
}

.iconfuwudianping:before {
  content: "\e63a";
}

.iconshenqingjiaru:before {
  content: "\e6bb";
}

.icongerenzhongxin:before {
  content: "\e610";
}

.iconbaoming:before {
  content: "\e632";
}

.iconicon-:before {
  content: "\e60f";
}

.iconbaidu:before {
  content: "\e63f";
}

.iconz-likeFill:before {
  content: "\e6c1";
}

.icondianzan2:before {
  content: "\e60d";
}

.iconxing:before {
  content: "\e639";
}

.iconqingkong:before {
  content: "\e623";
}

.iconwei-:before {
  content: "\e60a";
}

.icontubiaozhizuosvg-03:before {
  content: "\e601";
}

.icontubiaozhizuosvg-07:before {
  content: "\e602";
}

.icontubiaozhizuosvg-21:before {
  content: "\e603";
}

.icontubiaozhizuosvg-13:before {
  content: "\e604";
}

.icontubiaozhizuosvg-10:before {
  content: "\e605";
}

.icontubiaozhizuosvg-31:before {
  content: "\e606";
}

.icontubiaozhizuosvg-38:before {
  content: "\e607";
}

.icontubiaozhizuosvg-20:before {
  content: "\e608";
}

.icontubiaozhizuosvg-28:before {
  content: "\e609";
}


</style>
